package com.qq.BFMRSE.component;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.Timer;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import com.qq.BFMRSE.extractWord.SelectWord;
import com.qq.BFMRSE.extractWord.luceneOperation;

public class luenceProgress extends JFrame implements ActionListener, ChangeListener {
	    private JProgressBar progressbar;
		private JLabel proLabel;
		private luceneOperation lOperation;
		private Timer timer;
		public luceneOperation getlOperation() {
			return lOperation;
		}
		public void setlOperation(luceneOperation lOperation) {
			this.lOperation = lOperation;
		}
	
		public JProgressBar getProgressbar() {
			return progressbar;
		}
		public void setProgressbar(JProgressBar progressbar) {
			this.progressbar = progressbar;
		}
		public JLabel getProLabel() {
			return proLabel;
		}
		public void setProLabel(JLabel proLabel) {
			this.proLabel = proLabel;
		}
		public Timer getTimer(){
			return timer;
		}
		public void setTimer(Timer timer){
			this.timer=timer;
		}
	    public luenceProgress() {
	    	init();//对象初始化
	       this.setTitle("索引构建");
	       this.setBounds(100, 100, 400, 83);
	       this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	       this.setLocationRelativeTo(null);
	       this.setResizable(false);
	       Container contentPanel = this.getContentPane();
	       progressbar.setOrientation(JProgressBar.HORIZONTAL);
	       progressbar.setMinimum(0);
	       progressbar.setMaximum(100);
	       progressbar.setValue(0);
	       progressbar.setStringPainted(true);
	       progressbar.addChangeListener(this);
	       progressbar.setPreferredSize(new Dimension(300, 20));
	       progressbar.setBorderPainted(true);
	       progressbar.setBackground(Color.pink);
	       JPanel panel = new JPanel();
	       contentPanel.add(panel, BorderLayout.NORTH);
	       panel.add(proLabel);
	       contentPanel.add(progressbar, BorderLayout.CENTER);
	    }
	    public void init(){
	    	progressbar = new JProgressBar();
	    	proLabel = new JLabel("扫描文件构建luence索引", JLabel.CENTER);
	    	timer=new Timer(10, this);
	    	lOperation=new luceneOperation();
	    }
	   public void actionPerformed(ActionEvent e) {
		   if (e.getSource() == timer) {
	           int value = progressbar.getValue();
	           if (value < lOperation.getDocNum()){
	        	   double finish=lOperation.getDealedNum()*100.0/lOperation.getDocNum();
		           progressbar.setValue((int)finish);
	           }
	        	  
	           else {
	              timer.stop();
	              this.dispose();
	           }
	       }
	    }
	    public void stateChanged(ChangeEvent e1) {
	    	int value = progressbar.getValue();
	    	if (e1.getSource() == progressbar) {
	    		
	    		proLabel.setText("luence索引构建，目前已完成进度：" + value+ "%");
	    		proLabel.setForeground(Color.blue);
	       }
	    	}
	    public static void main(String[] args) {
	       new luenceProgress().setVisible(true);
	       
	    }
	    }